package cn.elves.model.award.controller;

import cn.elves.model.award.entity.po.Award;
import cn.elves.model.award.service.AwardService;
import cn.elves.model.entity.dto.response.ResponseDTO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("drawing")
public class AwardController {

    @Resource
    private AwardService awardService;

    @GetMapping("/award/page/{pageSize}/{pageNum}")
    public ResponseDTO<Page<Award>> awardPage(@PathVariable("pageSize") Integer pageSize, @PathVariable("pageNum") Integer pageNum) {
        return ResponseDTO.success(awardService.page(new Page<>(pageSize, pageNum)));
    }


    @GetMapping("/award/{id}")
    public ResponseDTO<Award> selectAward(@PathVariable("id") Long id) {
        return ResponseDTO.success(awardService.getById(id));
    }

    @PostMapping("/award")
    public ResponseDTO<Award> saveAward(Award award) {
        awardService.save(award);
        return ResponseDTO.success();
    }

    @PutMapping("/award")
    public ResponseDTO<Award> updateAward(Award award) {
        awardService.updateById(award);
        return ResponseDTO.success();
    }
}
